﻿let toDataSet stream = 
    let reader = Excel.ExcelReaderFactory.CreateOpenXmlReader(stream)
    reader.IsFirstRowAsColumnNames <- true
    reader.AsDataSet()

let values (dataset:System.Data.DataSet) (sheet:string) (columns:string[]) =
    let table =
        dataset.Tables
        |> Seq.cast<System.Data.DataTable>
        |> Seq.where(fun i -> i.TableName = sheet)
        |> Seq.exactlyOne
    let table = table.DefaultView.ToTable(false, columns)
    columns
    |> Seq.map(fun i -> System.String.Format("([{0}] IS NOT NULL)", i.Replace(@"\", @"\\").Replace(@"]", @"\]")))
    |> String.concat " OR "
    |> table.DefaultView.ToTable(false, columns).Select
    |> Seq.map(fun i -> i.ItemArray)

////////////////////////////////////////////////////////
let dataset = System.IO.File.OpenRead("Test.xlsx") |> toDataSet    
let columns = [|"名称"; "ID"; "数据"|]
let sheet = "Sheet1"

let data = values dataset sheet columns
data |> Seq.length |> printfn "%A"
data |> printfn "%A"
